Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add field to never drop data for a customer #17365

Closed
wants to merge 68 commits into from

Conversation

raquelmsmith
Copy link
Member

@raquelmsmith raquelmsmith commented Sep 8, 2023

Problem

See: https://posthog.slack.com/archives/C043VJ93L3B/p1694100638757679

We have a plan to make dropped data recoverable: https://posthog.slack.com/archives/C0374DA782U/p1694197775137269

However it would be nice if for larger customers we made sure that their data was never dropped.

Changes

Adds a field to the organization model never_drop_data. This field retrieved from the customer's billing response (added in https://github.com/PostHog/billing/pull/358). If true, then we never quota limit the org. However if they are over their limits, CS is notified via email.

How did you test this code?

Added a test.

@raquelmsmith raquelmsmith changed the title Feat/never drop data feat: add field to never drop data for a customer Sep 8, 2023
ee/billing/quota_limiting.py Show resolved Hide resolved
@raquelmsmith
Copy link
Member Author

@benjackwhite can you review again for my cache usage?

def send_over_quota_but_not_dropped_email_to_cs(organization_id: int) -> None:
organization: Organization = Organization.objects.get(pk=organization_id)
message = EmailMessage(
campaign_key=f"over_quota_but_not_dropped-{organization_id}-{timezone.now().timestamp()}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we perhaps use the campaign key to achieve the caching? If we make the key use the calendar week like now().isocalendar().week mixed with the year, then we will only send one message per week which achieves the caching mechanism and makes it easier to debug as we can easily inspect and modify postgres, whereas redis is a bit more transient.

Or alternatively extend the MessagingRecord to support multiple emails being sent for the same campaign_key with some sort of ttl. Like

message.send_again_after =  timedelta(days=7)
if message.send_again_after and last_message.sent_at <  now() - message.send_again_after:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make the key use the calendar week like now().isocalendar().week mixed with the year, then we will only send one message per week

Kind of... if a message is sent the last day of week 10, then another one will be sent the next day since it's week 11. So I don't think this is the right solution.

Or alternatively extend the MessagingRecord to support multiple emails being sent for the same campaign_key with some sort of ttl.

I can see other situations where we want to resend emails and have a record of the same exact email being sent on different days. I'll extend it in this way.

ee/billing/quota_limiting.py Outdated Show resolved Hide resolved
@benjackwhite
Copy link
Contributor

@raquelmsmith feel free to ping me in person if you want to get this over the line together

@raquelmsmith
Copy link
Member Author

raquelmsmith commented Sep 20, 2023

The test to make sure that this actually works was failing with:

E               django.db.utils.IntegrityError: duplicate key value violates unique constraint "posthog_messagingrecord_email_hash_campaign_key_6639a13f_uniq"
E               DETAIL:  Key (email_hash, campaign_key)=(a8ce72b2a64a75839fb5db5d3a48bff16cd0700a220d434936a6373fdbee8d72, campaign_2) already exists.

It seems to be not finding the new constraint that you added @frankh. I'm not certain how the migration you added works, is it expected that this test would be failing? I did add a commit to comment-out the test, but if it's not expected that it would be failing then prob don't want to merge this.

Also the migration validation check is failing, but without a useful error message, so I'm not sure if that is expected or if something is wrong with the migration.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

@posthog-bot posthog-bot closed this Oct 4, 2023
@raquelmsmith raquelmsmith reopened this Oct 5, 2023
@posthog-bot posthog-bot removed the stale label Oct 6, 2023
@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants